package com.utility;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Dictionary {
	
	
	public static Map<String,List<String>> readDictionary(String path){
		Map<String,List<String>> dict=new HashMap<String,List<String>>();
		File file = new File(path);
		try(BufferedReader br = new BufferedReader(new FileReader(file))) {
		    for(String line; (line = br.readLine()) != null; ) {
		        // process the line.
		    	char[] temp=line.toCharArray();
		    	Arrays.sort(temp);
		    	String sortedLine=temp.toString();
		    	if(dict.containsKey(sortedLine))
		    		dict.get(sortedLine).add(line);
		    	else{
		    		List<String>l=new ArrayList<String>();
		    		dict.put(sortedLine, l);
		    	}
		    }
		    // line is not visible here.
		    br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dict;
	}

	
	
}
